package lesosn03;

public class TestMain4 {

    public static void main(String[] args) {
        int c = 0;
        try {
            c = add(-0x7FFFFFFF, -0x7FFFFFFF);
        } catch (ArithmeticException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        System.out.println(c);
    }
    // throws方法，谁调用，谁倒霉，要处理异常
    public static int add(int a, int b) throws ArithmeticException, Exception {
        if (Integer.MAX_VALUE - b < a) {
            // Exception是最大的异常，是CheckedException
            Exception e = new Exception("a + b 值超过了最大值");
            throw e; // 抛出异常
        }
        if (Integer.MIN_VALUE - b > a) {
            throw new ArithmeticException("a + b 值太小，小于了最小值");
        }
        int r = a + b;
        return  r;
    }
}
